﻿

using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

using Gift.DAL;
using Gift.Model;
using Gift.Model.ENUM;

namespace WebSite.admin.warehouse
{
    public partial class warehouseGoodsOutList : BaseAdmin
    {
        readonly DALWarehouse theWarehouse = new DALWarehouse();
        protected void Page_Load(object sender, EventArgs e)
        {


            if (!base.IsPostBack)
            {
              //  base.ValidateLoginRule(ERule.WarehouseManager);
            
                this.BindGrid();

            }
        }
        private void BindGrid()
        {


            DataTable table = theWarehouse.GetWarehouseGoodsList(GetSqlWhere).Tables[0];
            Grid1.DataSource = table;
            Grid1.DataBind();
            Grid1.SelectedRowIndexArray = new int[] { };

        }
        string GetSqlWhere
        {
            
            get
            {
                StringBuilder sbWhere = new StringBuilder();
                sbWhere.AppendFormat("warehouseId in (select id from tbWarehouse where warehouseName like '%{0}%')", this.txtKeywords.Text.Trim());
                if (!string.IsNullOrEmpty(Request.QueryString["gid"]))
                {
                    sbWhere.Append("goodsId=" + Request.QueryString["gid"]);
                }
                return sbWhere.ToString();
            }
        }



        protected void btnSearch_Click(object sender, EventArgs e)
        {
            this.BindGrid();
        }

        protected void Grid1_PageIndexChange(object sender, ExtAspNet.GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;

        }

        protected void Grid1_Sort(object sender, ExtAspNet.GridSortEventArgs e)
        {
            DataTable table = theWarehouse.GetWarehouseGoodsList(GetSqlWhere).Tables[0];
            DataView view1 = table.DefaultView;
            view1.Sort = String.Format("{0} {1}", e.SortField, e.SortDirection);
            Grid1.DataSource = view1;
            Grid1.DataBind();
        }





    }
}